package GUI.Usuario;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.CardLayout;

import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import BBDD.ManageAlumno;
import BBDD.ManageModulo;
import BBDD.ManageNotasAlumno;
import DAO.AlumnoDAO;
import DAO.NotaAlumnoDAO;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class Notas extends JFrame {

	private JPanel contentPane;
	private JTextField txtPrimera;
	private JTextField txtSegunda;
	private JTextField txtTercera;
	private JTextField txtFinal;
	private Vector<NotaAlumnoDAO> notas;
	private ManageNotasAlumno controladorBD;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Notas frame = new Notas();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Notas() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 575, 523);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		
		JLabel lblalumno = new JLabel("#ALUMNO");
		lblalumno.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		JButton btnVolver = new JButton("Volver");
		btnVolver.setIcon(new ImageIcon(Notas.class.getResource("/Utilidades/volver.png")));
		btnVolver.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		JButton btnGuardar = new JButton("Guardar");
		btnGuardar.setIcon(new ImageIcon(Notas.class.getResource("/Utilidades/guardar.png")));
		btnGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				controladorBD = new ManageNotasAlumno();

				String query="INSERT INTO nota_alumno VALUES (" + txtPrimera.getText() + ",1,1,12,12,1)";
				
				
				controladorBD.updateNotasAlumno(query);
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(361, Short.MAX_VALUE)
					.addComponent(btnVolver)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnGuardar)
					.addGap(21))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(panel, GroupLayout.PREFERRED_SIZE, 533, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblalumno))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblalumno)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnGuardar, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnVolver, 0, 0, Short.MAX_VALUE))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		
		JButton btnRegistroDeNotas = new JButton("Registro de notas");
		btnRegistroDeNotas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DiarioNotas diarioNotas= new DiarioNotas();
				diarioNotas.setVisible(true);
			}
		});
		
		JLabel lblDiarioDeNotas = new JLabel("Diario de notas de aula.");
		
		JLabel lblObservaciones = new JLabel("Observaciones");
		
		JTextArea textArea = new JTextArea();
		
		JLabel lblerTrimestre = new JLabel("1\u00BA Trimestre");
		
		JLabel lblTrimestre = new JLabel("2\u00BA Trimestre");
		
		JLabel lblerTrimestre_1 = new JLabel("3\u00BA Trimestre");
		
		txtPrimera = new JTextField();
		txtPrimera.setColumns(10);
		
		txtSegunda = new JTextField();
		txtSegunda.setColumns(10);
		
		txtTercera = new JTextField();
		txtTercera.setColumns(10);
		
		JLabel lblNotasFinalesDe = new JLabel("Notas finales de trimestre");
		
		JLabel lblFinal = new JLabel("Final");
		
		txtFinal = new JTextField();
		txtFinal.setColumns(10);
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblObservaciones)
							.addContainerGap(487, Short.MAX_VALUE))
						.addGroup(gl_panel.createSequentialGroup()
							.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
								.addComponent(textArea, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
								.addGroup(gl_panel.createSequentialGroup()
									.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
										.addComponent(lblDiarioDeNotas)
										.addComponent(btnRegistroDeNotas))
									.addGap(224)
									.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
										.addGroup(gl_panel.createSequentialGroup()
											.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
												.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
													.addComponent(lblTrimestre)
													.addComponent(lblerTrimestre)
													.addComponent(lblerTrimestre_1))
												.addComponent(lblFinal))
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
												.addComponent(txtPrimera, Alignment.LEADING, 0, 0, Short.MAX_VALUE)
												.addComponent(txtSegunda, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
												.addComponent(txtTercera, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
												.addComponent(txtFinal, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)))
										.addComponent(lblNotasFinalesDe))
									.addGap(44)))
							.addGap(63))))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(18)
							.addComponent(lblDiarioDeNotas)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnRegistroDeNotas)
							.addPreferredGap(ComponentPlacement.RELATED, 83, Short.MAX_VALUE)
							.addComponent(lblObservaciones))
						.addGroup(gl_panel.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblNotasFinalesDe)
							.addGap(18)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblerTrimestre)
								.addComponent(txtPrimera, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(txtSegunda, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblTrimestre))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(txtTercera, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblerTrimestre_1))
							.addGap(18)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblFinal)
								.addComponent(txtFinal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 177, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		panel.setLayout(gl_panel);
		contentPane.setLayout(gl_contentPane);
	}
	
	public void fillTable(){
		controladorBD = new ManageNotasAlumno();
		controladorBD.loadNotasAlumno("Select * from nota_alumno"); 
		notas = controladorBD.getNotaAlumno();		
		for (int i = 0; i < notas.size(); i++) {
			System.out.println(notas.get(i).getIdNotaAlumno());
		System.out.println(notas.get(i).getEvaluacionNotaAlumno());
		
		}
		
	}
}
